from constants import DevLanguage

class Params:
    def __init__(self, name, style):
        self.name = name
        self.style = style

def generateMethod(devLanguage, name, paramsList, body, result = None, note = None):
    """[生成方法]

    Args:
        devLanguage ([DevLanguage]): [语言类型]
        name ([string]): [方法名称]
        paramsList ([List<Params>]): [参数列表]
        body ([string]): [方法体]
        result ([string], optional): [方法返回值]. Defaults to None.
    """
    method = None   
    if devLanguage == DevLanguage.kotlin:
        params_str = ""
        for item in paramsList:
            params_str += "%s: %s, "%(item.name, item.style)
        else:
            params_str = params_str[:-2]

        result_str = " "
        if result != None:
            result_str = ": %s "%result
        method = "func %s(%s)%s{\n%s}\n"%(name, params_str, result_str, body)
    elif devLanguage == DevLanguage.objc:
        params_str = ""
        for index, item in enumerate(paramsList):
            if index == 0:
                params_str = "With%s:(%s)%s"%(item.name.capitalize(), item.style, item.name)
            else:
                params_str += " %s:(%s)%s"%(item.name, item.style, item.name)

        result_str = ""
        if result == None:
            result_str = "void"
        else:
            result_str = result
        method = "+ (%s)%s%s {\n%s}\n"%(result_str, name, params_str, body)

    if note == None:
        return method

    return "//%s\n%s"%(note, method)


